
const app = getApp();
 Component
({
  options: {
    addGlobalClass: true
  },
  /**
 * 组件的初始数据
 */

  data: {
    buttom_note:'',
    yiqing:'',
    weather:'',
    user_number:0,
    inspector_number:0,
    day_in:0,
    day_out:0,
    swiperList: [
      'https://s1.ax1x.com/2020/06/11/tHm34O.jpg',
      'https://s1.ax1x.com/2020/06/11/tHnpGD.jpg',
      'https://s1.ax1x.com/2020/06/11/tHnkqI.jpg',
      'https://s1.ax1x.com/2020/06/11/tHnre1.jpg',
      'https://s1.ax1x.com/2020/06/11/tHunTx.jpg'
      ],
  },
  // onLoad:function(){


  pageLifetimes: {
  },
  methods:{
    //温度打卡
    recordTemp: function () {
      wx.navigateTo({
        url: '/pages/wendu/wendu',
      })
    },

  
//登记
recordIn:function(){
  var that1 = this;
  
  let tempCode;           
  let tempAddress; 
  if(getApp().globalData.isPost==true){      
  wx.scanCode({
    onlyFromCamera: true,           //只能从相机扫码
    scanType: ['qrCode'],           //只能扫二维码
    success: (res) => {
      console.log(res)
      tempCode = res.result.substring(1, 5)      //提取1-5位字符
      console.log(tempCode)
      console.log(getApp().globalData.room_id)
      tempAddress = res.result.substring(11,res.result.length-1)
      console.log(tempAddress)
      var temp=toJson(tempAddress) 
      console.log(temp)        
      if (1==2) {     //对识别码进行校验，正确的二维码才能进行下一步
        console.log("验证失败")       //验证失败，弹窗提示
        wx.showModal({
          title: '提示',
          content: '请扫描正确的二维码',
        })
      }
      else {
        console.log("进入解析")
        wx.vibrateShort()
        var objs = JSON.parse(temp)
        console.log(objs)
        for(var key in objs){
          console.log(key+":"+objs[key])
          if(key=="house_id"){
            console.log("设置房间号")
            getApp().globalData.room_id = objs[key]
          }else if(key=="identity"){
            console.log("设置身份证号")
            getApp().globalData.id_number=objs[key]
          }else if(key=="openId"){
            getApp().globalData.Uopenid =objs[key]
          }else if(key == "name"){
            getApp().globalData.name = objs[key]
          }else if(key=="warn"){
            getApp().globalData.warn = objs[key]
          }
        }
        console.log(getApp().globalData.Uopenid)
        console.log("验证成功")             //验证成功，进行页面跳转
        if(getApp().globalData.warn>=5){
          wx.showModal({
            title: '警告',
            content: '该用户体温数据多次异常',
          })
        }
        wx.navigateTo({
          url: '/pages/in/in?title=' + res.result.substring(5)
        })
      }
    },
  })
}else{
  wx.showModal({
    title: '提示',
    content: '请先绑定扫描人员账号',
  })
}
},

},
// })
})

function toJson(str)
{
return toArray(str);
}
//返回拼好json格式的字符串
function toArray(str)
{
  var list = str.split(",");
  var myStr = "{";
  for(var i=0;i<list.length;i++)
  {
    try{
      var keys = list[i].split("=");
      var key = Trim(keys[0]); 
      var value= Trim(keys[1]);
      if(i>0)
      {
        myStr += ",";
      }
      myStr += "\""+key+"\":\""+value+"\"";
    }catch(e)
    {
      continue;
    }
  }
  myStr += "}";
  return myStr;
}
//替换掉字符串中头尾的空格
function Trim(str){  
    return str.replace(/(^\s*)|(\s*$)/g, "");  
} 




